package com.aitaoxue.palx.ui;

import com.aitaoxue.palx.AppContext;
import com.aitaoxue.palx.db.GoodDBHelper;
import com.aitaoxue.palx.db.InfoDBHelper;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.os.Bundle;

public class SplashActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		init();
	}

	@Override
	protected void onStart() {
		super.onStart();

		// 判断是否第一次进入,如果是进入引导页
		boolean isFirst = AppContext.getInstance().getPersistPreferences()
				.getBoolean("isFirst", true);
		if (isFirst) {
			Editor editor = AppContext.getInstance().getPersistPreferences()
					.edit();
			editor.putBoolean("isFirst", false);
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
				editor.apply();
			} else {
				editor.commit();
			}
			startActivity(new Intent(this, WelcomeActivity.class));
		} else {
			startActivity(new Intent(this, LoginActivity.class));
		}
		finish();
	}

	// 执行一些初始化工作,比如创建一些静态数据库
	private void init() {
		initLocalDatabase();
	}

	private void initLocalDatabase() {
		InfoDBHelper.initDatabase();
		GoodDBHelper.initDataBase();
	}
	
	@Override
	public void onBackPressed() {
	}

}
